<?php
/**
 * @特惠赚、发送短信逻辑
 * Author: 小谢
 * Date: 2019-5-13
 */

namespace app\api\logic;
use sms\SmsApi;
use think\Model;
use think\Db;

/**
 * 发送短信逻辑
 * Class SendSms
 * @package Api\Logic
 */
class SendSmsLogic extends Model
{

   /**
    * @brief 发送短信
    */
    public function _exe($mobile,$rand) {
   	  $config_arr = $this->getSmsConfig();
   		$SmsApi  = new SmsApi($config_arr);
   		$tpl_arr = $this->getSmsTplContent();
   		$content = str_replace("$"."{code}",$rand,$tpl_arr['content']);
   		$return  = $SmsApi->sendSMS($mobile, $content);//发送短信
   		return $return;
    }
  
   /**
    * @brief 获取短信配置信息
    */
    public function getSmsConfig() {
  	 	$config_arr = M('sms_config')->find();
  	 	if($config_arr) {
 			return $config_arr;
  	 	}
  	 	ajaxReturn(['status'=>0,'errmsg'=>'未填写：sms_appkey','data'=>[]]);
    }

   /**
    * @brief 短信模板内容、登录场景短信模板内容
    */
    public function getSmsTplContent() {
  		$tpl = M('sms_template')->where(['send_scene'=>1])->find();
  		if($tpl) {
      		return $tpl;
  		}
  		ajaxReturn(['status'=>0,'errmsg'=>'Error：短信模板不存在','data'=>[]]);
    }

}